Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

3.6 Device Tree Source (.dts) File Format

Device Tree Source files are distinguished by the .dts filename extension suffix. The initial line of a valid source file must strictly contain the exact token declaration /dts-v1/;, where v1 identifies compliance with the first version of the Device Tree Specification. Leveraging the compilation preprocessor directive #include "file", a Device Tree Source file can reference and incorporate external hardware description layout files suffixed with the .dtsi extension. Except for omitting the standalone /dts-v1/; tag and the leading #include directives, the internal syntactical formatting rules for a .dtsi file match those of a standard .dts file. The following snippet illustrates a representative configuration slice extracted from the imx6dl-sabresd.dts platform file:

/dts-v1/;
#include "imx6dl.dtsi"
#include "imx6qdl.dtsi"
/ {
	model = "Freescale i.MX6 DualLite SABRESD Smart Device Board";
	compatible = "fsl,imx6dl-sabresd", "fsl,imx6dl";
	&battery {
       		offset-charger = <1485>;
        	offset-discharger = <1464>;
        	offset-usb-charger = <1285>;
	};
	/* ... */
};

In this context, offset-charger, offset-discharger, and offset-usb-charger represent proprietary hardware properties defined by NXP (formerly Freescale); their explicit parsing semantics and validation rules are mandated within matching vendor binding specifications.

3.6.1 Labels

Nodes or individual property definitions within the Device Tree can be preceded by a unique label identifier. A label must be 1 to 31 characters in length, consisting strictly of alphanumeric characters (a-z, A-Z, 0-9) or underscores (_), with the constraint that numeric digits 0-9 are prohibited from occupying the initial character slot. A label definition is declared by appending a colon (:) directly to the token string, typically isolated from the trailing node name or property declaration via whitespace.

When source code routines must target an absolute hierarchical path or resolve a specific node handle (phandle), developers can leverage a node's defined label as an abbreviated shorthand reference. This referencing mechanism is executed by prefixing the target label token with the ampersand character (&), as demonstrated by the &battery reference block in the preceding example. During the flattening process executed by the compiler, labels are translated into matching numeric phandle entries; consequently, raw textual label names do not persist inside the compiled binary .dtb blob.

3.6.2 Node and Property Definition Layout

A standard Device Tree node is composed of an optional label, a mandatory node name, an optional unit address, child nodes, and a localized block of properties. The universal layout syntax is defined as follows:

[label:] node-name[@unit-address] {
	[label:] property1 = value;
	[label:] property2 = value;
	[label:] child-node-name[@unit-address] {
            /* ... */
	};
};

A node block can encapsulate both explicit property strings and sub-nodes simultaneously. When mixing both types within a single node boundary, property definitions must precede child node declarations.

Hardware properties are classified into two primary presentation categories. If an attribute requires an explicit parameter assignment, its definition is formatted using the assignment operator (=):

[label:] property-name = value;

The assigned value payload can be expressed as an ASCII text string wrapped within double quotes (""), an array of 32-bit unsigned integer cells enclosed within angle brackets (<>), or a stream of raw hexadecimal byte values bound by square brackets ([]). If a node attribute requires a 64-bit integer allocation, it is represented as a sequence of two contiguous 32-bit cells (e.g., <0x7FFFF000 0x00000000>).

Property values can incorporate mathematical expressions, bitwise manipulations, and logical operations utilizing standard operators derived from C-language syntax rules. These operators include:

  • Arithmetic Operators: +, -, *, /, %

  • Bitwise Logical Operators: &, |, ^, ~, >>, <<

  • Logical Operators: &&, ||, !

  • Relational Operators: >, <, ==, >=, <=, !=

  • Conditional Ternary Operator: ?: (Format: Condition ? Value_If_True : Value_If_False)

An attribute can accommodate multiple distinct values or data types separated by a comma. For example:

compatible = "fsl,imx6qdl", "fsl,imx8";

The ampersand character (&) handles cross-references to phandles, labels, and paths. When an ampersand reference is nested inside a cell array (<>), the compiler maps the text label or absolute path to its underlying numeric phandle. Conversely, when an ampersand reference targets a node outside of a cell array context, the label expands to its fully qualified, absolute file system path string. The following blocks show the two equivalent syntactical pathways used to link the uart@1 peripheral to its upstream controller node intc@4000:

/* Method A: Reference via explicit symbolic node label */
uart1: uart@1 {
	interrupt-parent = <&intc1>;
};
/* Method B: Reference via full absolute path resolution syntax */
uart1: uart@1 {
	interrupt-parent = <&{/soc/intc@4000}>;
};
intc1: intc@4000 {
	interrupt-controller;
};

If a hardware attribute serves as an empty boolean indicator requiring no parameter data, it is declared as follows:

[label:] property-name;

The presence of an empty property string informs the operating system kernel that the target subsystem natively supports the associated hardware feature or peripheral configuration.

Copyright © 2026 Guangzhou eSmart Information Technology Co., Ltd. All Rights Reserved.
All content in this book is copyrighted by the author. For personal learning and exchange only. Commercial use without authorization is strictly prohibited. Email:

✉ 3348194517@qq.com | hai616878@gmail.com